import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemLogApi } from '#/api';

import { $t } from '#/locales';

export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'ip',
      label: $t('xtgl.log.action.ip'),
    },
    {
      component: 'Input',
      fieldName: 'accountName',
      label: $t('xtgl.log.action.createUser'),
    },
    {
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: [
          { label: $t('common.common.status.0'), value: 0 },
          { label: $t('common.common.status.1'), value: 1 },
        ],
      },
      fieldName: 'status',
      label: $t('xtgl.log.action.status'),
    },
    {
      component: 'Input',
      fieldName: 'openUrl',
      label: $t('xtgl.log.action.openUrl'),
    },
    {
      component: 'TimePicker',
      fieldName: 'createTime',
      label: $t('xtgl.log.action.actionTime'),
    },
  ];
}

export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'userName',
      componentProps: {
        clearable: true,
      },
      label: $t('xtgl.user.name'),
    },
    {
      component: 'Input',
      componentProps: {
        clearable: true,
      },
      fieldName: 'nickName',
      label: $t('xtgl.user.nickName'),
    },
    {
      component: 'Input',
      fieldName: 'telePhone',
      componentProps: {
        clearable: true,
      },
      label: $t('xtgl.user.telePhone'),
    },
    {
      component: 'select',
      fieldName: 'status',
      componentProps: {
        clearable: true,
        options: [
          { label: $t('common.common.enableStatus.0'), value: 0 },
          { label: $t('common.common.enableStatus.1'), value: 1 },
        ],
      },

      label: $t('xtgl.user.status'),
    },
    {
      component: 'DatePicker',
      componentProps: {
        clearable: true,
        type: 'datetimerange',
        rangeSeparator: '-',
        startPlaceholder: $t('common.common.time.startTime'),
        endPlaceholder: $t('common.common.time.endTime'),
      },
      fieldName: 'createTime',
      label: $t('common.common.audit.createTime'),
    },
  ];
}

export function useColumns<T = SystemLogApi.SystemLogAction>(
  onActionClick: OnActionClickFn<T>,
): VxeTableGridOptions['columns'] {
  return [
    { field: 'checkbox', type: 'checkbox', width: 60 },
    { title: '序号', field: 'id', width: 50 },
    {
      field: 'userName',
      title: $t('xtgl.user.name'),
      width: 150,
    },
    {
      field: 'nickName',
      title: $t('xtgl.user.nickName'),
      width: 100,
    },
    {
      field: 'unitName',
      title: $t('xtgl.user.unitName'),
      width: 200,
    },
    {
      field: 'headIcon',
      title: $t('xtgl.user.headIcon'),
      width: 150,
    },
    {
      field: 'telePhone',
      title: $t('xtgl.user.telePhone'),
      width: 150,
    },
    {
      field: 'status',
      title: $t('xtgl.user.status'),
      cellRender: { name: 'CellTag' },
      width: 100,
    },
    {
      field: 'createTime',
      minWidth: 100,
      title: $t('common.common.audit.createTime'),
    },
    {
      align: 'center',
      cellRender: {
        attrs: {
          nameField: 'id',
          onClick: onActionClick,
        },
        name: 'CellOperation',
        options: ['edit', 'delete'],
      },
      field: 'operation',
      fixed: 'right',
      headerAlign: 'center',
      showOverflow: false,
      title: $t('common.common.operation'),
      width: 200,
    },
  ];
}
